// 5. 责任链模式：安全事件处理
abstract class SafetyHandler {
    protected SafetyHandler nextHandler;

    public SafetyHandler setNext(SafetyHandler handler) {
        this.nextHandler = handler;
        return handler;
    }

    public abstract void handleEvent(SafetyEvent event);
}

class ObstacleHandler extends SafetyHandler {
    @Override
    public void handleEvent(SafetyEvent event) {
        if (event.getType() == SafetyEvent.Type.OBSTACLE) {
            System.out.printf("[障碍物处理] 检测到障碍物: %s\n", event.getDescription());
            // 模拟避障逻辑...
            event.setResolved(true);
        } else if (nextHandler != null) {
            nextHandler.handleEvent(event);
        }
    }
}

class WeatherHandler extends SafetyHandler {
    @Override
    public void handleEvent(SafetyEvent event) {
        if (event.getType() == SafetyEvent.Type.WEATHER) {
            System.out.printf("[天气处理] 恶劣天气: %s\n", event.getDescription());
            // 模拟天气应对逻辑...
            event.setResolved(true);
        } else if (nextHandler != null) {
            nextHandler.handleEvent(event);
        }
    }
}

class FaultHandler extends SafetyHandler {
    @Override
    public void handleEvent(SafetyEvent event) {
        if (event.getType() == SafetyEvent.Type.FAULT) {
            System.out.printf("[故障处理] 设备故障: %s\n", event.getDescription());
            // 模拟故障处理逻辑...
            event.setResolved(true);
        } else if (nextHandler != null) {
            nextHandler.handleEvent(event);
        }
    }
}

